/**
 * 
 */
package com.kerrykidz.common.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.common.dao.mapper.SysAttFileEntityMapper;
import com.kerrykidz.common.service.ICommonService;
import com.kerrykidz.dao.model.SysAttFileEntity;
import com.kerrykidz.membership.dao.mapper.GblCusCpndefEntityMapper;
import com.kerrykidz.membership.dao.model.GblCusCpndefEntity;
import com.kerrykidz.system.dao.mapper.GblSecBranEntityMapper;
import com.kerrykidz.system.dao.mapper.SecUsrEntityMapper;
import com.kerrykidz.system.dao.mapper.SysHolidayEntityMapper;
import com.kerrykidz.system.dao.mapper.SysParaEntityMapper;
import com.kerrykidz.system.dao.model.GblSecBranEntity;
import com.kerrykidz.system.dao.model.SecUsrEntity;
import com.kerrykidz.system.dao.model.SysParaEntity;
import com.rdp.framework.exception.RDPException;

/**
 * @author Tik
 * 
 */
@Service
public class CommonServiceImpl implements ICommonService {

	@Autowired
	private SysParaEntityMapper paraMapper;
	@Autowired
	private SecUsrEntityMapper userMapper;
	@Autowired
	private SysAttFileEntityMapper sysAttFileEntityMapper;

	//门店
	@Autowired
	private GblSecBranEntityMapper gblSecBranEntityMapper;

	@Autowired
	private GblCusCpndefEntityMapper cpndefMapper;
	@Autowired
	private SysHolidayEntityMapper holidayMapper;


	/**
	 * 根据KEY查询系统参数表中配置信息
	 * 
	 * @param key
	 * @date: 2014年8月12日
	 * @return: SysParaEntity
	 * @throws
	 */
	@Override
	public SysParaEntity findSysParaById(String key) {
		return paraMapper.findSysParaById(key);
	}

	/**
	 * 查找根据密码特殊折扣人
	 * 
	 * @param discountPassword
	 * @return
	 * @throws RDPException
	 * @date: 2014年8月13日
	 */
	@Override
	public SecUsrEntity findDiscountUser(String discountPassword, String branId) throws RDPException {
		List<SecUsrEntity> list = userMapper.findDiscountUser(discountPassword, branId);
		if (list.size() > 0)
			return list.get(0);
		return null;
	}

	public SysAttFileEntity findAttFileByPk(String pk) {
		return this.sysAttFileEntityMapper.findById(pk);
	}


	public List<GblSecBranEntity> getBranList(GblSecBranEntity branId)
			throws RDPException {
		return gblSecBranEntityMapper.getBranList(branId);
	}



	/**
	 * 根据优惠券ID，查询优惠券信息
	 * @param pkId
	 * @return
	 * @throws RDPException
	 * @date: 2014年8月28日
	 */
	@Override
	public GblCusCpndefEntity findCouponsById(String pkId) throws RDPException {
		return cpndefMapper.findCouponsById(pkId);
	}

	public void updateFilePath(SysAttFileEntity entity) throws RDPException {
			sysAttFileEntityMapper.updateEntity(entity);
	}

	@Override
	public List<GblSecBranEntity> findBranSearchList() throws RDPException {
		return gblSecBranEntityMapper.findBranSearchList();
	}
	
	public List<GblSecBranEntity> findAllBran() throws RDPException {
		return gblSecBranEntityMapper.findAllBran();
	}

	/**
	 * 判断当天是否为节假日
	 * @return
	 * 	1：是 0：否
	 * @throws RDPException
	 * @date: 2014年9月18日
	 */
	public boolean isHoliday() throws RDPException {
		return holidayMapper.isHoliday() > 0 ? true : false;
	}

	public List<GblSecBranEntity> getBranListForStock(String pkBranId)
			throws RDPException {
		return gblSecBranEntityMapper.getBranListForStock(pkBranId);
	}

	public void saveAttFile(SysAttFileEntity entity) throws RDPException {
		sysAttFileEntityMapper.insertAttFile(entity);
	}

	public void updateAttFile(SysAttFileEntity entity) throws RDPException {
		sysAttFileEntityMapper.updateEntity(entity);
	}

}
